conda install -c conda-forge pyhocontemp.config
client = {
user = adsf
password = adsf
}
blah = {
blah = {
blah = blah
}
}
import pyhocon
config = pyhocon.ConfigFactory.parse_file("temp.config")
type(config)
# <class 'pyhocon.config_tree.ConfigTree'>
isinstance(config, dict)
# True
config.get('blah')
# ConfigTree([('blah', ConfigTree([('blah', 'blah')]))])
config.get('blah', 'blah')
# ConfigTree([('blah', ConfigTree([('blah', 'blah')]))])
config.get('blah', 'blah').keys()
# odict_keys(['blah'])
config.get('blah', 'blah').get('blah')
# ConfigTree([('blah', 'blah')])TODO
# convert ConfigTree to string
config = pyhocon.HOCONConverter.convert(
config,
output_format='hocon',
indent=2,
compact=False
)
# write file
with open("temp.config", 'w') as f:
f.write(config)# convert ConfigTree to json string
config = pyhocon.HOCONConverter.to_json(config)
# convert json string to dict
config = json.loads(config)